package com.jlg.managers;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jlg.beans.groupon.ReviewRatingBean;
import com.julewa.db.DB;
import com.julewa.db.Identifier;

@Component
@SuppressWarnings("unchecked")
public class ReviewRatingManager {
	private @Autowired
    DB db;
    private @Autowired
    Identifier idsrv;
    
    public long save(ReviewRatingBean om)
    {
        long id = idsrv.generate("reviewrating");
        om.setId(id);
        boolean bool =  db.insert("reviewRating.insert", om);
        if (bool)
        {
            return id;
        } else
        {
            return -1;
        }
    }
    
    public boolean update(ReviewRatingBean om)
    {
        return db.update("rating.update", om);
    }

    public List<ReviewRatingBean> getAll()
    {
        return db.getList("rating.all", null);
    }

    public ReviewRatingBean findByParentId(long parentId)
    {
        Object obj = db.getObject("reviewRating.findByParentId", parentId);
        if (obj != null)
        {
            return (ReviewRatingBean) obj;
        }
        return null;
    }
    
    public ReviewRatingBean findByName(long parentId,String locName, int type)
    {
        Map map = new HashMap();
        map.put("name", locName);
        map.put("type", type);
        map.put("parentId", parentId);
        Object obj = db.getObject("reviewRating.findByName", map);
        if (obj != null)
        {
            return (ReviewRatingBean) obj;
        }
        return null;
    }
}
